package com.vision.core.cl.event;

import com.google.gwt.event.shared.EventHandler;
import com.google.gwt.event.shared.GwtEvent;
import com.vision.core.cl.event.UpdatedEvent.ModificationHandler;

/**
 * Event representing modification of an object. This can be used to send notifications
 * about an event for an object across multiple parts of the system without those
 * parts having references to each other. 
 *  
 * @author Mark
 *
 */
public abstract class UpdatedEvent<T> extends GwtEvent<ModificationHandler<T>> {

	/**
	 * The object that was updated.
	 */
	private T object;
	
	public UpdatedEvent(T object) {
		this.object = object;
	}
	
	public T getObject() {
		return object;
	}
	
	// Inherited Methods %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

	@Override
	protected void dispatch(ModificationHandler<T> handler) {
		handler.onUpdated(this);
	}
	
	// Interfaces %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
	
	public interface ModificationHandler<T> extends EventHandler {
		
		void onUpdated(UpdatedEvent<T> e);
		
	}

}
